Repository navigation
Fix bugs in truncation of vectors - #1797
Merged
Merged
Conversation
Member
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two bugs that show up when ring protocols truncate vectors:
floatingpoint.TruncInRing: when its arguments have different sizes, it masks every element of the vector with the same random value before opening it.sint.trunc_zeros: on a vector, it masks every element with the same random value, and it applies the first element's wrap-around correction to every element, so some elements come back wrong.The two bugs are in different files, but one call can reach both, so I'm sending them together. I'm opening a PR because I think I have a fix, so this seemed the quickest way to help. I saw that other potential security bugs have been reported in public issues here, so I hope that's ok. If you'd rather I report them another way next time, just let me know.
This snippet reproduces both bugs.
get_blockcallsTruncInRingthroughSplitInRingto cut the 8-bit block out of each value, andget_slicecallstrunc_zerosto split the block into two 4-bit fields:With
Scripts/compile-run.py -E ringor-E sy-rep-ring, it should print[5, 12, 0] [10, 3, 15]. Because of bug 2, the second list changes between runs, for example to[10, 19, 15]or[10, 3, -1]. Bug 1 doesn't change the output. To see it, printmaskedinTruncInRing: the differences between its elements, modulo 256, are the same on every run.Fix
TruncInRingdraws the random bits of its mask withget_random_bit(size=rev.size), so the mask has one value per element ofrev.sint.trunc_zerosis decorated with@vectorize, soTruncLeakyInRingruns at the size of the vector.Testing
I tested with
ringandsy-rep-ringonly.[5, 12, 0] [10, 3, 15]on every run. The differences between the elements ofmasked, printed inTruncInRingand inTruncLeakyInRing, change on every run with the fixes.print_ln('%s', sint(list(range(0, 1024, 16))).trunc_zeros(2, 10, False).reveal())should print[0, 4, ..., 252].trunc_zeroson a single value, and identical for all 39 programs inPrograms/Sourcethat compile with-R 64and no arguments.